<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/Css/wx_login.css">
    <script src="__PUBLIC__/js/jquery.min.2.1.1.js" type="text/javascript" charset="utf-8"></script>
    <title>小易出行</title>

    <script>
        function isapp() {
            if (/^.+(Mobile\/\w+)\s?$/.test(navigator.userAgent)) {
                // IOS端APP
                $('.blogo-reg a').css('display','block')
                console.log(111111)
            } else {
                // IOS端浏览器
                $('.blogo-reg a').css('display','block')

            }
        }
        isapp()
        function getCode() {

            var mobile = $('#mobile').val();

            var image_code = $('#image_code').val();
            var reg_mobile = /^(1(([357][0-9])|(47)|[8][0-9]))\d{8}$/;
            var reg_imagecode = /^[a-zA-Z0-9]{4}$/;
            if (!reg_mobile.test(mobile)) {
                $('#error').html('请填写正确的手机号');
                return false;
            }
            if (!reg_imagecode.test(image_code)) {
                $('#error').html('请填写正确的图片验证码');
                return false;
            }

            //首次调用add函数
            $.ajax({
                type: "post",
                url: "/index.php/Users/sendMsg",
                data: {mobile: mobile, image_code: image_code},
                dataType: "json",
                success: function (data) {
                    if (data.status == false) {
                        $('#error').html(data.msg);
                        $('#error').css('display', 'block');
                    } else {
                        //$('#code').val(data.msg);
                        $('#error').css('display', 'none');
                        add();
                        $('#verify_image').attr("src", "__CONTROLLER__/verify" + Math.random());
                    }
                }
            });
        }

        var timerc = 60; //全局时间变量（秒数）
        function add() { //加时函数
            if (timerc == 0) {
                $('#getCodeBtn2').css('display', 'none');
                $('#getCodeBtn').css('display', 'block');
                $("#getCodeBtn").html('重新获取');
                timerc = 60;
                return false;
            }
            if (timerc <= 60 && timerc > 0) {
                timerc--; //时间变量减1
                $("#getCodeBtn").css('display', 'none');
                $("#getCodeBtn2").html(Number(parseInt(timerc % 60 / 10)).toString() + (timerc % 10) + '秒后获取');
                $('#getCodeBtn2').css('display', 'block');
                setTimeout("add()", 1000);
            }
            ;
        };

        function checkMobile() {
            var mobile = $('#tel').val();
            var reg_mobile = /^(1(([357][0-9])|(47)|[8][0-9]))\d{8}$/;
            if (mobile == '') {
                $('#tel').val('请输入您的手机号码');
            } else if (!reg_mobile.test(mobile)) {
                $('#error').html('请填写正确的手机号');
            } else {
                $('#error').html('');
            }
        }

        function checkname() {
            var name = $('#name').val();
            if (name == '') {

                $('#error').html('请填写输入您的姓名');

            } else {
                $('#error').html('');

            }


        }

        function checkForm() {
            var mobile = $('#tel').val();
            var code = $('#code').val();
            var reg_code = /^[0-9]{6}$/;
            var reg_mobile = /^(1(([357][0-9])|(47)|[8][0-9]))\d{8}$/;
            $('#error').html('');

            if (!reg_mobile.test(mobile)) {
                $('#error').html('请填写正确的手机号');
                return false;
            } else {

                tj();
            }

            return false;
        }

        $(function () {
            $('input').focus(function () {
                $(this).css('color', '#000');
            });
        });

        function tj() {
            $.ajax({
                type: "POST",
                url: "__CONTROLLER__/addtel",

                cache: false,
                //dataType:json,
                data: $('#tab').serialize(),

                success: function (data) {

                    switch (data) {
                        case '0':
                            window.location.href = "__CONTROLLER__/index/id/1";

                            break;
                        case '1':
                            $('#error').html('发生未知错误');

                            break;
                        case '3':
                            $('#error').html('请输入正确的验证码信息');

                            break;
                        case '4':
                            $('#error').html('该手机号已经注册');

                            break;
                        default:
                            alert(1 + data);
                    }

                }
            });
        }
    </script>
    <style>
        .btn_yanzheng1 img {
            float: right;
            margin-right: 3%;

        }
    </style>
</head>

<body style="max-width:100%; max-height:100%;">
<div class="top2">绑定手机</div>
<form action="" method="post" id="tab">
    <input type="hidden" name="code" value="">
    <input type="hidden" name="url" id="url" value="Orders/stepOne">
    <div class="reg_conText">
        <div class="reg">
            <input class="vertify" type="text" name="name" id="name"
                   style="width:40%;color:#ccc;margin-left:10%;color:#ccc;" placeholder="请输入您的姓名" maxlength="6"
                   onblur="checkname()" onclick="if(this.value=='请输入您姓名'){this.value=''}">

        </div>
        <div class="reg">

            <input type="tel" name="tel" id="tel" style="color:#ccc;" value="请输入您的手机号码" maxlength="11"
                   onblur="checkMobile()" onclick="if(this.value=='请输入您的手机号码'){this.value=''}">

        </div>
        <br>
        <br>
        <br>
        <div class="reg">
            <input class="vertify" type="text" name="code" id="code" style="width:40%;color:#ccc;margin-left:10%;"
                   value="请先输入图片验证码" maxlength="4" onclick="if(this.value=='请先输入图片验证码'){this.value=''}">
            <div class="btn_yanzheng1" id="getCodeBtn3"><img src="__CONTROLLER__/verify"
                                                             onclick="this.src=this.src+'&'+Math.random()"
                                                             width="100px;"></div>

        </div>

        <br>
        <br>
        <br>


    </div>
    <div class="register">
        <div id="error" class="login" style="margin-top:0;"></div>
        <br>
        <div class="regist_now" onclick="checkForm()">马上绑定</div>
    </div>
</form>


</body>
</html>
